package edu.njust.cma.util;

import edu.njust.cma.pojo.Equipment;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.util.List;

public class ExcelUtil03 {

    // 生成Excel文件的方法
    public static XSSFWorkbook createExcelFile(List<Equipment> dataList) {
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet sheet = workbook.createSheet("Data");

        // 添加表头
        XSSFRow header = sheet.createRow(0);
        header.createCell(0).setCellValue("仪器设备编号");
        header.createCell(1).setCellValue("名称");
        header.createCell(2).setCellValue("型号/规格/等级");
        header.createCell(3).setCellValue("测量范围");
        header.createCell(4).setCellValue("设备购买年份");
        header.createCell(5).setCellValue("溯源方式");
        header.createCell(6).setCellValue("有效截止日期至");
        header.createCell(7).setCellValue("设备来源");

        // 填充数据
        int rowNum = 1;
        for (Equipment data : dataList) {
            XSSFRow row = sheet.createRow(rowNum++);
            row.createCell(0).setCellValue(data.getEquipmentNumber());
            row.createCell(1).setCellValue(data.getName());
            row.createCell(2).setCellValue(data.getDescription());
            row.createCell(3).setCellValue(data.getMeasuringRange());
            row.createCell(4).setCellValue(data.getPurchaseTime());
            row.createCell(5).setCellValue(data.getTraceway());
            row.createCell(6).setCellValue(data.getExpiryTime());
            row.createCell(7).setCellValue(data.getPurchaseMethod());
        }
        return workbook;
    }
}

